<script lang="ts" setup>
import { onShow, onLoad } from '@dcloudio/uni-app'


onShow(async () => {
   
    uni.getSystemInfo({
        success: (res) => {
            if (!res.locationEnabled || !res.locationAuthorized) {
                uni.showToast({
                    title: '请确保手机系统定位已开启',
                    icon: 'none',
                    duration: 2000,
                })
            }else{
                console.log(res,'定位已开启')
                uni.authorize({
                    scope: 'scope.userFuzzyLocation',
                    success(){
                        uni.getLocation({
                            type: 'wgs84',
                            success: function (res) {
                                console.log('当前位置的经度：' + res.longitude);
                                console.log('当前位置的纬度：' + res.latitude);
                            }
                        });
                    },
                    fail() {
                        console.log('haha')
                        uni.openSetting({
                            success(settingRes) {
                                if (settingRes.authSetting['scope.userLocation']) {
                                    console.log('可以调用 uni.getLocation 获取位置信息')
                                }else{
                                    console.log('用户未授权位置信息权限')
                                }
                            },
                            fail(){
                                console.log('shib')
                            }
                        })
                        // 定位权限授权失败
                        /** 
                        uni.showToast({
                            title: '请授权应用获取位置信息',
                            icon: 'none',
                            duration: 2000,
                        });
                        */
                    }
                })
                
                
            }
            
        }
    })
   
})
</script>

<template>
    <view class="container">
    </view>
</template>

<style lang="scss" scoped>
.container {
  position: absolute;
  width: 100%;
  height: 100%;
}
</style>